import {Component, Input, OnInit} from '@angular/core';
import {Router} from '@angular/router';

@Component({
    selector: 'app-carousel',
    templateUrl: './carousel.component.html',
    styleUrls: ['./carousel.component.scss']
})
export class CarouselComponent implements OnInit {

    constructor(
        private router: Router
    ) {
    }
    @Input() tagData: any;

    slideOpts = {
        effect: 'flip',
        autoplay: true
    };
    imgList: any[];

    targetObj: any = {
        forward: {},  // 跳转相关参数
        path: '',     // 跳转路由
        bat: [],        // 记录每次跳转的参数
        way: ''
    };

    ngOnInit() {
        console.log(this.tagData);
        this.imgList = this.tagData.field;
    }

    goto(obj) {
        if (obj.type === 'url') {
            const url = obj.target;
            window.open(url);
        } else {
            this.targetObj.forward = {
                pageId: obj.target,
                params: {},
                sessionId: localStorage.getItem('sessionId')
            };
            this.targetObj.path = 'home/tab2';
            this.targetObj.way = 'page';
            this.targetObj.bat.push(this.targetObj.forward);
            this.router.navigate([this.targetObj.path], {queryParams: this.targetObj.forward});
            localStorage.setItem('targetObj', JSON.stringify(this.targetObj));
        }
    }

}
